<template>
<div class="page">
	<!-- page-content has additional login-screen content -->
	<div class="page-content login-screen-content">
		<div class="login-screen-title">{{$root.PSI.productionName}}</div>
		<!-- Login form -->
		<form>
			<div class="list">
				<ul>
					<li class="item-content item-input">
						<div class="item-inner">
							<div class="item-title item-label">登录名</div>
							<div class="item-input-wrap">
								<input id="editLoginName" type="text" name="loginName"
									placeholder="登录名"> <span class="input-clear-button"></span>
							</div>
						</div>
					</li>
					<li class="item-content item-input">
						<div class="item-inner">
							<div class="item-title item-label">密码</div>
							<div class="item-input-wrap">
								<input id="editPassword" type="password" name="password"
									placeholder="密码"> <span class="input-clear-button"></span>
							</div>
						</div>
					</li>
				</ul>
			</div>
			<div class="list">
				<ul>
					<li><a href="#" class="item-link list-button" @click="doLogin">登录</a></li>
				</ul>
				<div class="block-footer">{{$root.PSI.demoLoginInfo}}</div>
			</div>
		</form>
	</div>
</div>
</template>

<script>
	return {
		methods : {
			doLogin : function() {
				var me = this;
				var app = me.$app;
				var $$ = me.$$;

				var loginName = $$("#editLoginName").val();
				var password = $$("#editPassword").val();
				if (!loginName) {
					app.dialog.alert("没有输入登录名");
					return;
				}
				if (!password) {
					app.dialog.alert("没有输入登录密码");
					return;
				}

				var loginURL = app.data.PSI.baseURI + "H5/User/doLogin";
				var params = {
					loginName : loginName,
					password : password,
					isH5: "1"
				};

				app.preloader.show();

				app.request.post(loginURL, params, function(data) {
					app.preloader.hide();
					if (data.success) {
						app.data.PSI.userIsLoggedIn = true;
						me.$router.refreshPage();
					} else {
						app.dialog.alert(data.msg);
					}
				}, function() {
					app.preloader.hide();
					app.dialog.alert("网络错误");
				}, "json");
			}
		}
	};
</script>
